home *** CD-ROM | disk | FTP | other *** search
- on checkStates tStates
- tCollisions = []
- repeat with i = 1 to tStates.count
- if tStates[i][#crashed] = 1 then
- next repeat
- end if
- repeat with ii = i + 1 to tStates.count
- if tStates[ii][#crashed] = 1 then
- next repeat
- end if
- t = stateCollidingWithState(tStates[i], tStates[ii])
- if t <> 0 then
- tCollisions.append([i, ii, t])
- end if
- end repeat
- end repeat
- return tCollisions
- end
-
- on stateCollidingWithState tState1, tState2
- if getDistanceSquared(tState1[#position], tState2[#position]) > 10000 then
- return 0
- end if
- tForward = 47 / 2
- tBackward = -47 / 2
- tWidth = 37 / 2
- tPos = tState1[#position]
- tAngle = tState1[#angle]
- tRF = tPos + (getVector(tAngle) * tForward) + (getVector(tAngle + (PI / 2)) * tWidth)
- tLF = tPos + (getVector(tAngle) * tForward) - (getVector(tAngle + (PI / 2)) * tWidth)
- tRB = tPos + (getVector(tAngle) * tBackward) + (getVector(tAngle + (PI / 2)) * tWidth)
- tLB = tPos + (getVector(tAngle) * tBackward) - (getVector(tAngle + (PI / 2)) * tWidth)
- tPoints1 = [tRF, tLF, tRB, tLB]
- tPos = tState2[#position]
- tAngle = tState2[#angle]
- tRF = tPos + (getVector(tAngle) * tForward) + (getVector(tAngle + (PI / 2)) * tWidth)
- tLF = tPos + (getVector(tAngle) * tForward) - (getVector(tAngle + (PI / 2)) * tWidth)
- tRB = tPos + (getVector(tAngle) * tBackward) + (getVector(tAngle + (PI / 2)) * tWidth)
- tLB = tPos + (getVector(tAngle) * tBackward) - (getVector(tAngle + (PI / 2)) * tWidth)
- tPoints2 = [tRF, tLF, tRB, tLB]
- repeat with tPoint in tPoints1
- if point_inside_rot_rect(tPoint[1], tPoint[2], tPoints2[1][1], tPoints2[1][2], tPoints2[2][1], tPoints2[2][2], tPoints2[3][1], tPoints2[3][2]) then
- return tPoint
- end if
- end repeat
- repeat with tPoint in tPoints2
- if point_inside_rot_rect(tPoint[1], tPoint[2], tPoints1[1][1], tPoints1[1][2], tPoints1[2][1], tPoints1[2][2], tPoints1[3][1], tPoints1[3][2]) then
- return tPoint
- end if
- end repeat
- return 0
- end
-